package com.yupi.usercenter.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedisConfigClient {
    private String host;
    private int port;
    @Bean
    public RedissonClient redissonClient() {

        Config RedisConfig = new Config();
        String redisHost = String.format("redis://%s:%d", host, port);
        RedisConfig.useSingleServer().setAddress(redisHost).setDatabase(3);
        RedissonClient redissonClient = Redisson.create(RedisConfig);
        return redissonClient;
//        RedisConfig.useClusterServers().addNodeAddress("redis://127.0.0.1:6379");
//        return RedisConfig.
    }
}
